<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
    <title>p78复习父子组件之间的传值</title>
</head>
<body>
    <div id="app">
        <com1 :parentmsg="msg" @func="getSonMsg"></com1>
        <h1>这是子组件传递来的值-{{sonmsg}}</h1>
    </div>
    <template id="tmp1">
        <div>
            <h1>这是组件--{{parentmsg}}</h1>
            <input type="button" value="向父子间传值" @click="getmsg">
        </div>
    </template>
    <script>
        var com1={
            template:"#tmp1",
            props:["parentmsg"],
            data(){
                return {
                    msg:"这是子组件的data"
                }
            },
            methods:{
                getmsg(){
                    this.$emit("func",this.msg);
                }
            }
        }
        var vm=new Vue({
        el:"#app",
        data:{
            msg:"这是vm的data数据",
            sonmsg:""
        },
        methods:{
            getSonMsg(data){
                this.sonmsg=data;
            }
        },
        filters:{},
        directives:{},
        components:{
            com1
        }
    })
    </script>
</body>
</html>